﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PokerClient.Connection.CommandHandlers;
using PokerClient.VisualDisp;

namespace PokerClient.Commands.CommandHandlers
{
	class currGameHandler : absHandler
	{
		String message = " ";
		gameState gs;
		
		private Table myTable;
		private Client myClient;

		public currGameHandler(Table table, Client myClient)
		{
			// TODO: Complete member initialization
			this.myTable = table;
			this.myClient = myClient;
		}
		public override void assignCommand(string commands)
		{
			this.commands = commands.Split(' ',',');
		}

		public override string work()
		{
			
			String gameid = commands[0], potsize = commands[1];
			
			switch(commands[4].ToUpper())
			{
				case "FLOP:":
					gs = gameState.FLOP;
					message = "FLOP";
					break;
				case "TURN:":
					gs = gameState.TURN;
					message = "TURN";
					break;
				case "RIVER:":
					gs = gameState.RIVER;
					message = "RIVER";
					break;
				case "SHOWHANDS:":
					gs = gameState.SHOWHANDS;
					message = "SHOWHANDS";
					break;
				case "NOTSTARTED":
					gs = gameState.NOTSTARTED;
					message = "NotStarted";
					break;
				default:
					message = "PREFLOP";
					gs = gameState.PREFLOP;
					break;
			}
			return message;
		}

		public override void analyze()
		{
			String[] temp;
			
				switch (gs)
				{
					case gameState.FLOP:
						myTable.revealFlop(commands[5], commands[6], commands[7]);
						temp = commands[8].Split('[', ']', '|');
						myTable.updateBig(temp[1]);
						myTable.updateSmall(temp[2]);
						break;
					case gameState.TURN:
						myTable.revealFlop(commands[5], commands[6], commands[7]);
						myTable.revealTurn(commands[8]);
						temp = commands[9].Split('[', ']', '|');
						myTable.updateBig(temp[1]);
						myTable.updateSmall(temp[2]);
						break;
					
					case gameState.RIVER:
						myTable.revealFlop(commands[5], commands[6], commands[7]);
						myTable.revealTurn(commands[8]);
						myTable.revealRiver(commands[9]);
						temp = commands[10].Split('[', ']', '|');
						myTable.updateBig(temp[1]);
						myTable.updateSmall(temp[2]);
						break;
					case gameState.SHOWHANDS:
						break;
					case gameState.NOTSTARTED:
						break;
					default:
						myTable.updateStatus(message);
						temp = commands[5].Split('[', ']', '|');
						if (temp.Length > 2)
						{
							myTable.updateBig(temp[1]);
							myTable.updateSmall(temp[2]);
						}
						break;
				}

				//myTable.updateCurrPlayer(commands[4]);
			}
			
		
	}

	enum gameState
	{
		PREFLOP,
		FLOP,
		TURN,
		RIVER,
		SHOWHANDS,
		NOTSTARTED
	}
}

